package cn.monkey.transport.netty;

import cn.monkey.transport.core.Exchange;
import io.netty.channel.Channel;

public class SimpleNettyExchangeFactory implements NettyExchangeFactory<NettyExchange> {
    @Override
    public NettyExchange apply(String key, Exchange exchange, Channel channel) {
        if (exchange == null) {
            return new SimpleNettyExchange(key, channel);
        }
        if (exchange instanceof NettyExchange nettyExchange) {
            return nettyExchange;
        }
        throw new IllegalArgumentException("exchange should be NettyExchange type or null");
    }
}
